﻿using System;
using System.Collections.Generic;
using System.Text;
using BlueFinity.mvNET.CoreObjects;
using mvLibrary.Helpers.Utils;

namespace mvLibrary.Helpers.BaseClass
{
    public class BasicMvItem : mvItem
    {
        public BasicMvItem(string item)
            : base(item)
        {
        }

        public BasicMvItem()
        {
        }
        public string[] GetSplittedElementsFromAttribute(int attributeIndex)
        {
            return FenkUtils.SplitMultivalueAttributes(getData(attributeIndex).ToString());
        }

        public string GetValueFromAttributeInPosition(int attributeIndex, int position)
        {
            var value = GetSplittedElementsFromAttribute(attributeIndex);

            try
            {
               return value[position];
            }
            catch (Exception)
            {
                return string.Empty;
            }
        }

        public int GetIntValueFromAttributeInPosition(int attributeIndex, int position)
        {
            var value = this.GetValueFromAttributeInPosition(attributeIndex, position);
            return string.IsNullOrEmpty(value) ? FenkUtils.ZERO : Convert.ToInt32(value);
        }

        public object GetAttribute(int attributeIndex)
        {
            return getData(attributeIndex);
        }

        public void SetAttribute(int attributeIndex, int value)
        {
            setData(attributeIndex, value);
        }
    }
}
